<template>
  <div>
    <span>活动车型</span>
    <div class="box_01">
      <FilterTable
        ref="table"
        :columns="columns"
        :dataSource="list1"
        :isColumnFilter="false"
        :isToperInfo="false"
        :isSelectColumn="false"
        :isPagination="false"
        :onSyncTableData="syncTableFun"
        :onColumnsChange="columns => (this.columns = columns)"
      >
        <template slot="controls" slot-scope="props">
          <el-button size="small" type="primary" icon="el-icon-plus" @click="addActscopeHandle()">新增</el-button>
        </template>
      </FilterTable>
    </div>
    <!-- <span :style="{display : 'block',paddingTop: '5px'}">活动车辆</span> -->
    <!-- <div class="box_02">
             <FilterTable
        ref="table2"
        :columns="columns2"
        :dataSource="list2"
        :isColumnFilter = false
        :isToperInfo    = false
        :isSelectColumn = false
        :onColumnsChange="columns => this.columns2 = columns"
      >
         <template slot="controls" slot-scope="props">
           <el-button
             size="small"
             type="primary"
             icon="el-icon-upload2"
             @click="importHandle()"
           >导入</el-button>
            <el-button
             size="small"
             type="primary"
             icon="el-icon-download"
           >导出</el-button>
            <el-button
             size="small"
             type="primary"
             icon="el-icon-download"
           >模板下载</el-button>
         </template>
      </FilterTable>
    </div>-->
    <BaseDialog :visible.sync="visibleAddactscope" title="选择车型" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }" destroyOnClose>
      <AddActcsope ref="asddActcsope" @closeaddAct="closeAddactcsope" />
    </BaseDialog>
    <BaseDialog :visible.sync="visiblefwhddr" title="服务活动导入" :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '30px' }" destroyOnClose>
      <fwhddr ref="fwhddr" @closeFwhddr="closeAddfwhddr" />
    </BaseDialog>
  </div>
</template>
<script>
import fwhddr from './AddActcsope/fwhddr';
import AddActcsope from './AddActcsope/addActcsope';
import { dictionary } from '@/utils/dictMixin';
import { detailsActscope, detailsActscopeNoPage } from '@/api/repair/repair/activitesManage';
let _this;
export default {
  name: 'Actcsope',
  components: {
    AddActcsope,
    fwhddr
  },
  mixins: [dictionary],
  props: ['type', 'detaildata'],
  data() {
    // this.BaseTable = null;
    return {
      visiblefwhddr: false,
      visibleAddactscope: false,
      columns: this.createTableColumns(),
      columns2: this.createTableColumns2(),
      list1: [],
      list2: [],
      tableData: []
    };
  },
  created() {
    _this = this;
  },
  mounted() {
    if (_this.type == 2) {
      _this.detailsActscope();
    }
  },
  methods: {
    // 获取活动车型方法
    async detailsActscope() {
      // let res = await detailsActscope(_this.detaildata);
      // _this.$refs.table.$refs.pageTable.EXECUTE_INSERT(res.data.rows);
      this.$refs.table.START_LOADING();
      try {
        let res = await detailsActscopeNoPage(_this.detaildata);
        if (res.resultCode == 200) {
          _this.$refs.table.$refs.pageTable.EXECUTE_INSERT(res.data);
        }
      } catch (err) {
        console.log(err, '获取车型主列表失败');
      } finally {
        this.$refs.table.STOP_LOADING();
      }
    },
    importHandle() {
      this.visiblefwhddr = true;
    },
    // 传给父组件的数据
    syncTableFun(val) {
      this.tableData = val;
      _this.$emit('changeEmptyone', this.tableData);
    },
    closeAddfwhddr(val) {
      this.visiblefwhddr = false;
    },
    addActscopeHandle() {
      this.visibleAddactscope = true;
    },
    ceshi(val) {
      // console.log(JSON.stringify(this.tableData), 'hexj001');
      // _this.$emit('changeEmptyone', _this.list1);
    },
    closeAddactcsope(val) {
      if (val != false) {
        let flag1 = false;
        val.forEach(item => {
          let flag = 0;
          val.forEach(x => {
            if (item.BRAND_ID == x.BRAND_ID && item.SERIES_ID == x.SERIES_ID && item.MODEL_ID == x.MODEL_ID) {
              flag += 1;
            }
          });
          if (flag > 1) {
            flag1 = true;
          }
        });
        if (flag1) {
          this.$notify.error({
            title: '错误',
            message: '选中数据存在重复'
          });
          return;
        }
        let pd1 = false;
        let pd2 = false;
        let pd3 = false;
        let pd4 = false;
        if (this.tableData.length > 0) {
          this.tableData.forEach(x => {
            val.forEach(item => {
              if (x.BRAND_ID == item.BRAND_ID) {
                pd1 = true;
              }
              if (x.SERIES_ID == item.SERIES_ID) {
                pd2 = true;
              }
              if (x.MODEL_ID == item.MODEL_ID) {
                pd3 = true;
              }
              // if (x.CONFIG_NAME == item.CONFIG_NAME) {
              //       pd4 = true
              // }
            });
          });
        }
        if (pd1 && pd2 && pd3) {
          this.$notify.error({
            title: '错误',
            message: '请勿重复提交'
          });
          return;
        }
        this.visibleAddactscope = false;
        this.$refs.table.$refs.pageTable.EXECUTE_INSERT(val);
      } else if (val == false) {
        this.visibleAddactscope = false;
      }
    },
    // 活动车型表单数据删除
    delete(val) {
      let a = [];
      a.push(val);
      if (val.ITEM_ID != null && val.ITEM_ID != '' && val.ITEM_ID != undefined) {
        this.$emit('handleDeleted', val);
      }
      this.$refs.table.$refs.pageTable.EXECUTE_DELETE(a);
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          fixed: 'left',
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: '',
          fixed: 'left',
          // sorter: true,
          render: props => {
            return (
              <el-button size="mini" type="text" onClick={() => this.delete(props.row)}>
                删除
              </el-button>
            );
          }
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true
        },
        {
          title: '品牌',
          dataIndex: 'BRAND_NAME1',
          fixed: 'left'
          // sorter: true,
        },
        {
          title: '车系',
          dataIndex: 'SERIES_NAME',
          sorter: true
        },
        {
          title: '车型',
          dataIndex: 'MODEL_NAME1',
          sorter: true
        }
      ];
    },
    createTableColumns2() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true
          // render: props => {
          //   return <span>{props.row.index + 1}</span>;
          // }
        },
        {
          title: '操作',
          dataIndex: '',
          fixed: 'left',
          sorter: true
          // render: props => {
          //   return <span>{}</span>;
          // }
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true
        },
        {
          title: '责任维修站',
          dataIndex: 'DUTY_ENTITY',
          sorter: true
        },
        {
          title: 'VIN',
          dataIndex: 'VIN',
          sorter: true
        }
      ];
    },
    async getFwhdHdclList(row) {
      const res = await getFwhdHdclList(row, {
        creditTimes: 1.0,
        afterlabour: 0,
        zkAmountLabour: 0,
        afterDiscountAmountPart: 0,
        zkAmountPart: 0,
        fag: 'U',
        labourList: '',
        partList: '',
        subjoinList: '',
        modelList: '',
        vehicleList: '',
        order: 'asc',
        limit: 10,
        offset: 0,
        dmsFuncId: 35100010,
        _: 1565681747515
      });
      this.list2 = res.rows;
    },
    async getFwhdHdcxList(row) {
      const res = await getFwhdHdcxList(row, {
        creditTimes: 1.0,
        afterlabour: 0,
        zkAmountLabour: 0,
        afterDiscountAmountPart: 0,
        zkAmountPart: 0,
        fag: 'U',
        labourList: '',
        partList: '',
        subjoinList: '',
        modelList: '',
        vehicleList: '',
        order: 'asc',
        limit: 10,
        offset: 0,
        dmsFuncId: 35100010,
        _: 1565681747515
      });
      this.list1 = res.rows;
    }
  }
};
</script>

<style lang="less" scoped>
.box_01 {
  margin-top: 10px;
}
.box_02 {
  margin-top: 10px;
}
</style>
